export function displaceArray(arrOld) {
  console.log(arrOld);
  // 进行旧数组分组
  let arrA = [];
  for (let i=0;i<arrOld.length;i++){
    arrA.push(arrOld[i].toString().substring(0,1));
  }
  // 进行分组数组去重
  arrA = arrA.filter(function(item,index){
    return arrA.indexOf(item,0) === index;
  });
  console.log(arrA);
  // 进行旧数组二次分组
  let arrB = [];
  for (let i=0;i<arrA.length;i++){
    let arr = [];
    for (let j=0;j<arrOld.length;j++){
      if (arrA[i] === arrOld[j].substring(0,1)){
        arr.push(arrOld[j]);
      }
    }
    arrB.push(arr);
  }
  console.log(arrB);
  let arrC = [];
  // 对二次分组的数组进行同级处理
  for (let i=0;i<arrB.length;i++){
    let flag = false;
    let max = 0;
    for (let j=0;j<arrB[i].length;j++){
      let width = arrB[i][j].toString().length;
      if (width === max){
        flag = true;
      }
      max = width;
    }
    if (flag){
      let arr = [];
      for (let j=0;j<arrB[i].length;j++){
        let arr2 = [];
        arr2.push(arrB[i][j]);
        arr.push(arr2);
      }
      for (let j=0;j<arr.length;j++){
        for (let k=0;k<arr[j][k];k++){
          let width = arr[j][k].toString().length;
          switch (width) {
            case 3:
              arr[j].push(arr[j][k].toString().substring(0,1));
              break;
            case 5:
              arr[j].push(arr[j][k].toString().substring(0,1));
              arr[j].push(arr[j][k].toString().substring(0,3));
              break;
          }
        }

      }
      // for (let j=0;j<(arrB[i].length - 2);j++){
      //   for (let k=0;k<arr.length;k++){
      //     if (arrB[i][j].indexOf(arr[k]) === -1){
      //       arr[k].push(arrB[i][j]);
      //     }
      //   }
      // }
      for (let i=0;i<arr.length;i++){
        arrC.push(arr[i]);
      }
    } else {
      arrC.push(arrB[i]);
    }
  }
  // 分组排序
  for (let i=0;i<arrC.length;i++){
    arrC[i].sort(sortNumber);
  }
  console.log(arrC);
  // 进行最终分组
  let arrAll = [];// 最终的数组
  for (let i=0;i<arrC.length;i++){
    // 1,104,10400
    for (let j=0; j<arrC[i].length; j++) {
      let arr = [];
      for (let k=0; k<(j+1); k++){
        if (arr.indexOf(arrC[i][k]) === -1) {
          arr.push(arrC[i][k]);
        }
      }
      arrAll.push(arr);
    }

  }
  console.log(arrAll);
  return arrAll;
}
function sortNumber(a, b)
{
  return a - b
}

